// pages/mysport/order/order.js
var util = require("../../../utils/util.js")
const gd = getApp().globalData;
const net = require('../../../utils/net.js');
var posting = false;
var dialog = null;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    logo: "../../../assets/image/logo.png",
    search_day:"",
    page:1,
    list: [],
    ordertype:1,
    course_status:""
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var title = "所有预约";
    var course_status=  "";
    if(options.type==2){
      title = "已完成私教课"
      course_status = 1;
    }else{

    }
    wx.setNavigationBarTitle({
      title
    })
    this.setData({
      course_status
    })
  }, bindDateChange(e){
    this.setData({
      search_day:e.detail.value
    })
  },
  getlist(issearch){
    if (posting) return;
    posting = true;
    var that = this;
    wx.showLoading({})
    net.request({
      url: '/AllOrder',
      data: {
        shop_id: gd.shop_id,
        member_id: gd.id,
        page: that.data.page,
        course_status: that.data.course_status,
        search_day: that.data.search_day
      }, success(res) {
        var dt = res.data;
        console.log("allorder",dt);
        if (dt.flag) {
          if (dt.data.length > 0) {
            var page = that.data.page + 1;
            var tmplist = issearch?[]:that.data.list;
            for (var i = 0; i < dt.data.length; ++i) {
              tmplist.push(dt.data[i]);
            }
            that.setData({
              page: page,
              list: tmplist
            })
          } else {

          }
        } else {
          dialog.showDialog({
            msg: dt.msg
          })
        }
      }, fail(res) {

      }, complete() {
        posting = false;
        wx.hideLoading();
        that.scrollloading(false);
        wx.stopPullDownRefresh();
      }
    })
  },
  search(){
    this.setData({
      list:[],
      page:1
    })
    this.getlist(true);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    dialog = this.selectComponent("#dialog");
    this.getlist();
  }, toscroll(e) {
    this.setData({
      scrolltmp: e.detail.scrollTop
    })
  }, tolower() {
    this.scrollloading(true);
    this.getlist();
  }, scrollloading(isshow) {
    var that = this;
    let top = 0;
    let delay = 0;
    if (isshow) {
      top = that.data.list.length * 71;
    } else {
      delay = 100;
      top = that.data.scrolltmp - 71;
    }
    setTimeout(function () {
      that.setData({
        scrollTop: top
      })
    }, delay);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      list: [],
      page: 1
    })
    this.getlist(true);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})